import {
  IsEmail,
  IsOptional,
  IsString,
  MaxLength,
  IsEnum,
  IsNotEmpty,
  MinLength,
} from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import { UserGender } from '../entities/user.entity';

export class UpdateUserDto {
  @ApiProperty({ description: '昵称', example: '新昵称', required: false })
  @IsOptional()
  @IsString({ message: '昵称必须是字符串' })
  @MaxLength(50, { message: '昵称最多50个字符' })
  nickname?: string;

  @ApiProperty({
    description: '邮箱',
    example: 'new@example.com',
    required: false,
  })
  @IsOptional()
  @IsEmail({}, { message: '邮箱格式不正确' })
  @MaxLength(100, { message: '邮箱最多100个字符' })
  email?: string;

  @ApiProperty({
    description: '手机号',
    example: '13900139000',
    required: false,
  })
  @IsOptional()
  @IsString({ message: '手机号必须是字符串' })
  @MaxLength(20, { message: '手机号最多20个字符' })
  phone?: string;

  @ApiProperty({
    description: '性别',
    example: '1',
    enum: UserGender,
    required: false,
  })
  @IsOptional()
  @IsEnum(UserGender, { message: '性别值不正确' })
  gender?: UserGender;
}

export class UpdatePasswordDto {
  @ApiProperty({ description: '旧密码', example: 'oldpassword' })
  @IsNotEmpty({ message: '旧密码不能为空' })
  @IsString({ message: '旧密码必须是字符串' })
  oldPassword: string;

  @ApiProperty({ description: '新密码', example: 'newpassword' })
  @IsNotEmpty({ message: '新密码不能为空' })
  @IsString({ message: '新密码必须是字符串' })
  @MinLength(6, { message: '新密码至少6个字符' })
  @MaxLength(50, { message: '新密码最多50个字符' })
  newPassword: string;

  @ApiProperty({ description: '确认新密码', example: 'newpassword' })
  @IsNotEmpty({ message: '确认新密码不能为空' })
  @IsString({ message: '确认新密码必须是字符串' })
  confirmPassword: string;
}
